package com.dtborad.myblog.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dtborad.myblog.entity.Categories;
import com.dtborad.myblog.entity.Tags;
import com.dtborad.myblog.mapper.TagsMapper;
import com.dtborad.myblog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TagServiceImpl extends ServiceImpl<TagsMapper, Tags> implements TagService {

    @Autowired
    private TagsMapper tagsMapper;
    @Override
    public Page<Tags> getAllTagsByPageSize(int pagenum, int pagesize, String name) {
        LambdaQueryWrapper<Tags> wrapper = new LambdaQueryWrapper<>();
        if(StrUtil.isNotBlank(name)){
            wrapper = wrapper.like(Tags::getTagname, name);
        }else{
            //查询全部数据
            return tagsMapper.selectPage(new Page<>(pagenum, pagesize), null);
        }
        return tagsMapper.selectPage(new Page<>(pagenum, pagesize), wrapper);
    }
}
